export class PlayerProgressReader {
  /** 转换成游戏中的年份 */
  static convertTimeAdvanced(
    createTime: Date | number | string,
    currentTime?: Date | number | string
  ): number {
    try {
      // 统一转换为时间戳
      let createTimestamp: number;
      if (typeof createTime === 'number') {
        createTimestamp = createTime;
        if (createTimestamp <= 0) return 0;
      } else if (createTime instanceof Date) {
        createTimestamp = createTime.getTime();
      } else {
        createTimestamp = new Date(createTime).getTime();
      }

      let currentTimestamp: number;
      if (currentTime === undefined) {
        currentTimestamp = Date.now();
      } else if (typeof currentTime === 'number') {
        currentTimestamp = currentTime;
      } else if (currentTime instanceof Date) {
        currentTimestamp = currentTime.getTime();
      } else {
        currentTimestamp = new Date(currentTime).getTime();
      }

      // 验证时间戳有效性
      if (isNaN(createTimestamp) || isNaN(currentTimestamp)) {
        throw new Error('无效的时间格式');
      }

      const timeDiff = currentTimestamp - createTimestamp;

      if (timeDiff < 0) {
        return 0;
      }

      const minutesDiff = timeDiff / (1000 * 60);
      const years = Math.floor(minutesDiff / 15);

      return years;
    } catch (error) {
      console.error('时间转换错误:', error);
      return 0;
    }
  }
}
